package com.common.doc.xsl;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

/**
 * @author YunDa11
 * 
 */
public class CellManager
{
	public static HSSFCell createCell(HSSFSheet sheet, int rowIndex,
			int colIndex)
	{
		HSSFRow row = sheet.createRow(rowIndex);
		HSSFCell cell = row.getCell((short) colIndex);
		if (cell == null)
			cell = row.createCell((short) colIndex);
		HSSFCellStyle style = cell.getCellStyle();

		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
		style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
		style.setBorderRight(HSSFCellStyle.BORDER_THIN);
		style.setBorderTop(HSSFCellStyle.BORDER_THIN);
		style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		cell.setCellStyle(style);

		return cell;
	}
	

	public static HSSFCell createCell1(HSSFSheet sheet, int rowIndex,
			int colIndex)
	{
		HSSFRow row = sheet.createRow(rowIndex);
		// HSSFCell cell = row.getCell((short)colIndex);
		// if(cell==null)
		HSSFCell cell = row.createCell((short) colIndex);
		HSSFCellStyle style = cell.getCellStyle();

		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		style.setBorderBottom(HSSFCellStyle.BORDER_NONE);
		style.setBorderLeft(HSSFCellStyle.BORDER_NONE);
		style.setBorderRight(HSSFCellStyle.BORDER_NONE);
		style.setBorderTop(HSSFCellStyle.BORDER_NONE);
		style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		cell.setCellStyle(style);

		return cell;
	}
	
	public static HSSFCell createTitle(HSSFSheet sheet, int rowIndex,
			int colIndex)
	{
		HSSFRow row = sheet.createRow(rowIndex);
		HSSFCell cell = row.getCell((short) colIndex);
		if (cell == null)
			cell = row.createCell((short) colIndex);
		HSSFCellStyle style = cell.getCellStyle();

		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		style.setBorderBottom(HSSFCellStyle.BORDER_NONE);
		style.setBorderLeft(HSSFCellStyle.BORDER_NONE);
		style.setBorderRight(HSSFCellStyle.BORDER_NONE);
		style.setBorderTop(HSSFCellStyle.BORDER_NONE);
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		cell.setCellStyle(style);

		return cell;
	}
	
	public static HSSFCell createTitleNoStyle(HSSFSheet sheet, int rowIndex,
			int colIndex)
	{
		HSSFRow row = sheet.createRow(rowIndex);
		HSSFCell cell = row.getCell((short) colIndex);
		if (cell == null)
			cell = row.createCell((short) colIndex);
		HSSFCellStyle style = cell.getCellStyle();
		
		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellStyle(style);
		return cell;
	}
	
	public static HSSFCell createCellNoStyle(HSSFSheet sheet, int rowIndex,
			int colIndex)
	{
		HSSFRow row = sheet.createRow(rowIndex);
		HSSFCell cell = row.getCell((short)colIndex);
		if(cell==null)
			 cell = row.createCell((short) colIndex);
		HSSFCellStyle style = cell.getCellStyle();

		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//		cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellStyle(style);
		return cell;
	}
}
